<?php

require_once __DIR__ . '/../autoload.php';
//引入用户信息检查类
use src\DataBase;
$username=$_COOKIE['school']['username'];
$newpassword=trim($_POST["newpassword"]);
$db= new DataBase\DataBaseOperate('139.196.124.180','school','user1','Mcx857264','utf8');
$selectResult=$db->update('studentInfo',array('password'=>$newpassword),array('studentNumber'=>$username));
if($selectResult){
	$expire=time()+60*60*24*30*6;
    setcookie("password",$newpassword,$expire);
	$modifyPasswordCount=$_COOKIE[$username."modifyPasswordCount"];
	$modifyPasswordCount=$modifyPasswordCount-1;
	$time=time()+60*60*24*30*54;
	setcookie($username."modifyPasswordCount",$modifyPasswordCount,$time);
    exit(json_encode(array('code'=>1,'msg'=>'修改成功!')));
}else{
    exit(json_encode(array('code'=>0,'msg'=>'修改失败!')));
}